package com.untour.im.common.response;

import com.untour.im.common.enums.CodeEnum;
import com.untour.im.common.enums.ResultEnum;

public class CallResult<T> {

	private String code;

	private String message;

	private T data;

	public static <T> CallResult<T> success(T data) {
		return new CallResult<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(),
				data);
	}

	public static <T> CallResult<T> success(String message, T data) {
		return new CallResult<>(ResultEnum.SUCCESS.getCode(), message, data);
	}

	public static CallResult<?> failed() {
		return new CallResult<>(ResultEnum.FAILED.getCode(),
				ResultEnum.FAILED.getMessage(), null);
	}

	public static CallResult<?> failed(String message) {
		return new CallResult<>(ResultEnum.FAILED.getCode(), message, null);
	}

	public static CallResult<?> failed(CodeEnum codeEnum) {
		return new CallResult<>(codeEnum.getCode(), codeEnum.getMessage(), null);
	}
	public static CallResult<?> failed(CodeEnum codeEnum,String message) {
		return new CallResult<>(codeEnum.getCode(), message, null);
	}

	public CallResult() {
	}

	public CallResult(String code, String message, T data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public static <T> CallResult<T> instance(String code, String message, T data) {
		CallResult<T> result = new CallResult<>();
		result.setCode(code);
		result.setMessage(message);
		result.setData(data);
		return result;
	}

}
